package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.modles.CategorySampleInfo;

/**
 * Created by lanouhn on 16/8/29.
 */
public class SampleListViewAdapter extends BaseAdapter{
    private Context context;
    private CategorySampleInfo sampleInfo;


    public SampleListViewAdapter(Context context, CategorySampleInfo sampleInfo) {
        this.context = context;
        this.sampleInfo = sampleInfo;
    }

    @Override
    public int getCount() {
        return sampleInfo.getData().getCategories().size();
    }

    @Override
    public Object getItem(int position) {

        return sampleInfo.getData().getCategories().get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }


    static class ViewHolder{
        public TextView tv;
        public View mView;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            holder=new ViewHolder();
            convertView=View.inflate(context, R.layout.sample_listview_item,null);
            holder.tv= (TextView) convertView.findViewById(R.id.sample_list_item);
            holder.mView=convertView.findViewById(R.id.view_item);
            convertView.setTag(holder);

        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.tv.setText(sampleInfo.getData().getCategories().get(position).getName());
        if (position==selectItem){
            convertView.setBackgroundColor(Color.WHITE);
            holder.tv.setTextColor(Color.RED);
            holder.mView.setVisibility(View.VISIBLE);
        }else{
            convertView.setBackgroundColor(Color.TRANSPARENT);
            holder.tv.setTextColor(Color.BLACK);
            holder.mView.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }
    public void setSelectItem(int selectItem){
        this.selectItem=selectItem;
    }
    private int selectItem=-1;
}
